import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { PreloaderConfig } from "../../common/preLoadPage/PreloaderConfig";
import { FileType } from "../../../com/gengine/resource/FileType";
import { ResourceInfo } from "../../../com/gengine/resource/info/ResourceInfo";
import { PathConst } from "../../common/global/PathConst";
import { ParamsConst } from "../../common/global/ParamsConst";
import { ResourceManager } from "../../../com/gengine/resource/ResourceManager";
type int = number;
//class ResConfig
    
    export  class ResConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            if (ResConfig._instance != null) 
            {
                throw new Error(" ResConfig 单例 ");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc3=null;
            var loc1=ConfigManager.instance.getByteArrayByFileName("assets.vas");
            loc1.uncompress();
            loc1.position = 0;
            var loc2=loc1.readObject() as Object;
            var loc4=0;
            var loc5=loc2;
            for(loc3 of loc5) 
            {
                break;
            }
            if (typeof loc3 === "array") 
            {
                this.newWrite(loc2);
            }
            else 
            {
                this.write(loc2);
            }
            return;
        }

        protected write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (PreloaderConfig.preResName) 
            {
                this._maxLength = PreloaderConfig.preResName.length;
            }
            var loc4=0;
            var loc5=arg1;
            for(loc3 of loc5) 
            {
                loc1 = FileType.getLoaderInfoByType(loc3.type as string);
                if (loc1) 
                {
                    loc2 = new loc1(loc3);
                }
                else 
                {
                    loc2 = new ResourceInfo(loc3);
                }
                loc2.loaclPath = loc2.path;
                loc2.path = PathConst.mainPath + loc2.path;
                if (this._maxLength > this._length) 
                {
                    this._index = PreloaderConfig.preResName.indexOf(loc2.name);
                    if (this._index != -1) 
                    {
                        loc2.path = PreloaderConfig.preResUrl[this._index] + "?v=" + ParamsConst.instance.preLoaderVersion;
                        loc2.loaclPath = loc2.path;
                        loc2.path = PathConst.mainPath + loc2.path;
                        var loc6;
                        var loc7=((loc6 = this)._length + 1);
                        loc6._length = loc7;
                    }
                }
                ResourceManager.addResource(loc2);
            }
            return;
        }

        protected newWrite(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            if (PreloaderConfig.preResName) 
            {
                this._maxLength = PreloaderConfig.preResName.length;
            }
            var loc8=0;
            var loc9=arg1;
            for (loc6 in loc9) 
            {
                loc5 = arg1[loc6];
                var loc10=0;
                var loc11=loc5;
                for(loc7 of loc11) 
                {
                    loc7.path = loc6 + "/" + loc7.name;
                    loc4 = (loc3 = loc7.name).lastIndexOf(".");
                    loc3 = loc3.slice(loc4);
                    loc7.type = loc3;
                    loc1 = FileType.getLoaderInfoByType(loc7.type as string);
                    if (loc1) 
                    {
                        loc2 = new loc1(loc7);
                    }
                    else 
                    {
                        loc2 = new ResourceInfo(loc7);
                    }
                    loc2.loaclPath = loc2.path;
                    loc2.path = PathConst.mainPath + loc2.path;
                    if (this._maxLength > this._length) 
                    {
                        this._index = PreloaderConfig.preResName.indexOf(loc2.name);
                        if (this._index != -1) 
                        {
                            loc2.path = PreloaderConfig.preResUrl[this._index] + "?v=" + ParamsConst.instance.preLoaderVersion;
                            loc2.loaclPath = loc2.path;
                            loc2.path = PathConst.mainPath + loc2.path;
                            var loc12;
                            var loc13=((loc12 = this)._length + 1);
                            loc12._length = loc13;
                        }
                    }
                    ResourceManager.addResource(loc2);
                }
            }
            return;
        }

        public getInfoByName(arg1: string): ResourceInfo
        {
            return ResourceManager.getInfoByName(arg1);
        }

        public getUrlByName(arg1: string): string
        {
            var loc1=ResourceManager.getInfoByName(arg1);
            if (loc1) 
            {
                return loc1.path;
            }
            return "";
        }

        public static get instance(): ResConfig
        {
            if (ResConfig._instance == null) 
            {
                ResConfig._instance = new ResConfig();
            }
            return ResConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_length: int;

        /* internal */ /* var */_maxLength: int;

        /* internal */ static /* var */_instance: ResConfig;
    }
